home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-25 | 15.7 KB | 663 lines | [TEXT/MPS ] |
-
- {[d-,h-,k+,o=100,q+,r+,rec+,t=2,u+,:+,j=15/20/25/30/35/40/45/50/57/1$]} {Pasmat opts!}
-
- PROGRAM SVEdit;
- (*
- SVEditMain.p
-
- Version 3.0d8
-
- Copyright © SRL Data 1992, 1993
-
- All rights reserved
-
- Produced by : SRL Data
- Originally Developed for UK.DTS
-
- *)
-
- {The main routines for the SVEdit example program}
-
- {* This example is brought to you for the purposes of exploration and experimentation of
- System 7.0. It is not intended to form the basis of your own programs- but try out the code-
- that's what it's there for *}
-
- {System 7.0 specifics-:
-
- We check the configuration on startup to see if we are running on a pre-7.0
- machine. Much as we'd like to handle both environments in 7Edit, we thought
- exiting gracefully under pre-7.0 systems was the best solution.
-
-
- Notice the additions to the main event loop to support section events and the
- despatching of AppleEvents.
-
- New for 3.0d2 :
-
- 21-Feb-92 : NH : Fix type into subscribers
- 26-Feb-92 : NH : ShowBorders grey when no window
- 27-Feb-92 : NH : Test menu and gCurrSection zapped
- 5-Mar-92 : NH : Create Publisher - event driven (ish)
- 27-Mar-92 : NH : Update menu status before MenuKey
-
- Changes for 3.0d5 :
-
- 11-Aug-92 : NH : Quit via AppleEvent
- 21-Aug-92 : NH : Keystroke recording added
- Filing uses errors not booleans
- }
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, Types, Traps, Menus, Packages, PPCToolbox, Editions,
- Printing, AppleEvents, AEObjects, SVEditGlobals, SVEditUtils, SVEditions, SVAppleEvents,
- SVEditWindow, SVEditFile;
-
- {-----------------------------------------------------------------------}
- {*---------- Standard Main routines --------------*}
- {-----------------------------------------------------------------------}
-
- {$S Main}
-
- PROCEDURE MaintainCursor;
-
- VAR
- pt : POINT;
- wPtr : WindowPtr;
- savePort : GrafPtr;
- theDoc : DPtr;
-
- BEGIN
- wPtr := FrontWindow;
- IF Ours(wPtr) THEN
- BEGIN
- theDoc := DPtrFromWindowPtr(wPtr);
- GetPort(savePort);
- SetPort(wPtr);
- GetMouse(pt);
- IF (theDoc^.theText <> NIL) THEN
- IF PtinRect(pt, theDoc^.theText^^.viewRect) THEN
- SetCursor(editCursor)
- ELSE
- SetCursor(arrow)
- ELSE
- SetCursor(arrow);
-
- IF theDoc^.theText <> NIL THEN
- TEIdle(theDoc^.theText);
-
- SetPort(savePort);
- END;
- END;
-
- {$S Main}
-
- PROCEDURE MaintainMenus;
-
- VAR
- theDoc : DPtr;
- firstWindow : WindowPtr;
- currSection : SectHandle;
-
- BEGIN
- firstWindow := FrontWindow;
- IF NOT (Ours(firstWindow)) THEN
- BEGIN
- EnableItem(myMenus[fileM], fmNew);
- EnableItem(myMenus[fileM], fmOpen);
- DisableItem(myMenus[fileM], fmClose);
- DisableItem(myMenus[fileM], fmSave);
- DisableItem(myMenus[fileM], fmSaveAs);
- DisableItem(myMenus[fileM], fmRevert);
- DisableItem(myMenus[fileM], fmPrint);
- DisableItem(myMenus[fileM], fmPageSetup);
-
- DisableItem(myMenus[editM], cPublisher);
- DisableItem(myMenus[editM], cSubscriber);
- DisableItem(myMenus[editM], cOptions);
- DisableItem(myMenus[editM], cBorders);
-
- IF firstWindow <> NIL THEN
- BEGIN
- EnableItem(myMenus[editM], undoCommand);
- EnableItem(myMenus[editM], cutCommand);
- EnableItem(myMenus[editM], copyCommand);
- EnableItem(myMenus[editM], pasteCommand);
- EnableItem(myMenus[editM], clearCommand);
- END;
- END
- ELSE
- BEGIN
- theDoc := DPtrFromWindowPtr(firstWindow);
- EnableItem(myMenus[editM], pasteCommand);
- EnableItem(myMenus[editM], cBorders);
- EnableItem(myMenus[fileM], fmClose);
- EnableItem(myMenus[fileM], fmSaveAs);
- EnableItem(myMenus[fileM], fmPrint);
- EnableItem(myMenus[fileM], fmPageSetup);
-
- IF (theDoc^.dirty) THEN
- EnableItem(myMenus[fileM], fmRevert)
- ELSE
- DisableItem(myMenus[fileM], fmRevert);
-
- IF ((theDoc^.dirty) AND (theDoc^.everSaved)) THEN
- EnableItem(myMenus[fileM], fmSave)
- ELSE
- DisableItem(myMenus[fileM], fmSave);
-
- DisableItem(myMenus[editM], undoCommand);
-
- IF (theDoc^.theText^^.selEnd - theDoc^.theText^^.selStart) < 0 THEN
- BEGIN
- DisableItem(myMenus[editM], cutCommand);
- DisableItem(myMenus[editM], copyCommand);
- DisableItem(myMenus[editM], clearCommand);
- DisableItem(myMenus[editM], cPublisher);
- END
- ELSE
- BEGIN
- EnableItem(myMenus[editM], cutCommand);
- EnableItem(myMenus[editM], copyCommand);
- EnableItem(myMenus[editM], clearCommand);
- EnableItem(myMenus[editM], cPublisher);
- END;
-
- currSection := GetSection(theDoc^.theText^^.selStart,
- theDoc^.theText^^.selEnd,
- theDoc);
- IF (currSection <> NIL) THEN
- BEGIN
- DisableItem(myMenus[editM], cPublisher);
- DisableItem(myMenus[editM], cSubscriber);
- EnableItem(myMenus[editM], cOptions);
- IF currSection^^.fSecthandle^^.kind = stPublisher THEN
- SetItem(myMenus[editM], cOptions, 'Publisher Options…')
- ELSE
- SetItem(myMenus[editM], cOptions, 'Subscriber Options…');
- END
- ELSE
- BEGIN
- EnableItem(myMenus[editM], cPublisher);
- EnableItem(myMenus[editM], cSubscriber);
- DisableItem(myMenus[editM], cOptions);
- END;
- END;
- END;
-
- {$S Main}
-
- PROCEDURE SetUpCursors;
-
- VAR
- hCurs : CursHandle;
-
- BEGIN
- hCurs := GetCursor(1);
- editCursor := hCurs^^;
- hCurs := GetCursor(watchCursor);
- waitCursor := hCurs^^;
- END;
-
- {$S Main}
-
- PROCEDURE SetUpMenus;
-
- VAR
- i : INTEGER;
-
- BEGIN
-
- myMenus[appleM] := GetMenu(appleID);
- AddResMenu(myMenus[appleM], 'DRVR');
- myMenus[fileM] := GetMenu(fileID);
- myMenus[editM] := GetMenu(editID);
- myMenus[fontM] := GetMenu(fontID);
- AddResMenu(myMenus[fontM], 'FONT');
- myMenus[sizeM] := GetMenu(sizeID);
- myMenus[styleM] := GetMenu(styleID);
-
- FOR i := appleM TO kLastMenu DO
- InsertMenu(myMenus[i], 0);
-
- SetItemStyle(myMenus[styleM], cPlain, []);
- SetItemStyle(myMenus[styleM], cBold, [bold]);
- SetItemStyle(myMenus[styleM], cItalic, [italic]);
- SetItemStyle(myMenus[styleM], cUnderline, [underline]);
- SetItemStyle(myMenus[styleM], cOutline, [outline]);
- SetItemStyle(myMenus[styleM], cShadow, [shadow]);
- SetItemStyle(myMenus[styleM], cCondense, [condense]);
- SetItemStyle(myMenus[styleM], cExtEND, [extEND]);
-
- SetShortMenus;
- END;
-
- PROCEDURE DoFile(theItem: INTEGER);
-
- VAR
- alertResult : INTEGER;
- theDoc : DPtr;
- theFSSpec : FSSpec;
- fileErr : OSErr;
- thePSetup : TPrint;
- myErr : OSErr;
-
- BEGIN
- CASE theItem OF
- fmNew: IssueAENewWindow;
-
- fmOpen:
- IF (GetFile(theFSSpec)=noErr) THEN
- fileErr := IssueAEOpenDoc(theFSSpec);
-
- fmClose: IssueCloseCommand(FrontWindow);
-
- fmSave,
- fmSaveAs:
-
- BEGIN
- theDoc := DPtrFromWindowPtr(FrontWindow);
-
- IF (theDoc^.everSaved=false) OR (theItem=fmSaveAs) THEN
- BEGIN
- fileErr := GetFileNameToSaveAs(theDoc);
- IF (fileErr<>noErr) AND (fileErr<>userCanceledErr) THEN
- FileError('error saving ', theDoc^.theFileName)
- ELSE
- fileErr := IssueSaveCommand(theDoc^.theWindow, @theDoc^.theFSSpec);
-
- IF (fileErr = noErr) THEN
- SetWTitle(theDoc^.theWindow, theDoc^.theFSSpec.name);
- END
- ELSE
- fileErr := IssueSaveCommand(theDoc^.theWindow, NIL);
-
- END;
-
- fmRevert:
- BEGIN
- SetCursor(arrow);
- theDoc := DPtrFromWindowPtr(FrontWindow);
-
- ParamText('Revert to the last saved version of ', theDoc^.theFileName, '', '');
- alertResult := Alert(AdviseAlert, NIL);
- CASE alertResult OF
- aaSave:
- IF IssueRevertCommand(theDoc^.theWindow) <> noErr THEN
- FileError('error reverting ', theDoc^.theFileName);
-
- OTHERWISE;
- END; {of CASE}
- END; {fmRevert}
-
- fmPageSetUp: BEGIN
- theDoc := DPtrFromWindowPtr(FrontWindow);
- IF DoPageSetup(theDoc) THEN
- BEGIN
- thePSetup := theDoc^.thePrintSetup^^;
- IssuePageSetupWindow(theDoc^.theWindow, thePSetup);
- END;
- END;
-
- fmPrint: IssuePrintWindow(FrontWindow);
-
- fmQuit : myErr := IssueQuitCommand;
-
- END; {of case}
- END;
-
- {$S Main}
-
- PROCEDURE DoCommand(mResult: Longint);
-
- VAR
- theItem : INTEGER;
- err : INTEGER;
- result : Longint;
- name : Str255;
- theDocument : DPtr;
-
- BEGIN
- theDocument := DPtrFromWindowPtr(FrontWindow);
-
- theItem := LoWord(mResult);
-
- CASE HiWord(mResult) OF
-
- appleID:
- IF theItem = aboutItem THEN
- BEGIN
- SetCursor(arrow);
- result := Alert(258, NIL);
- END
- ELSE
- BEGIN
- GetItem(myMenus[appleM], theItem, name);
- err := OpenDeskAcc(name);
- SetPort(FrontWindow);
- END;
-
- fileID: DoFile(theItem);
-
- editID:
- BEGIN
- IF SystemEdit(theItem - 1) = FALSE THEN;
-
- CASE theItem OF
-
- cutCommand : IssueCutCommand(theDocument);
-
- copyCommand : IssueCopyCommand(theDocument);
-
- pasteCommand : IssuePasteCommand(theDocument);
-
- clearCommand : IssueClearCommand(theDocument);
-
- selectAllCommand :
- BEGIN
- IF theDocument <> NIL THEN
- TESetSelect(0, theDocument^.theText^^.teLength, theDocument^.theText);
- END;
-
- cPublisher : IssueCreatePublisher(theDocument);
-
- cSubscriber: DoSubscribe(theDocument);
-
- cOptions : DoSectionOptions(theDocument);
-
- cBorders : IssueShowBorders(theDocument^.theWindow, NOT theDocument^.showBorders);
-
- END; {of CASE}
- ShowSelect(theDocument);
-
- END;
-
- fontID: IssueFontCommand(theDocument, theItem);
-
- sizeID: IssueSizeCommand(theDocument, theItem);
-
- styleID: IssueStyleCommand(theDocument, theItem);
-
- END; {of CASE}
- END;
-
- {$S Main}
-
- PROCEDURE DoMouseDown(myEvent: EventRecord);
-
- VAR
- whichWindow : WindowPtr;
- p : POINT;
- dragRect : Rect;
- theDoc : DPtr;
-
- BEGIN
- p := myEvent.where;
- CASE (FindWindow(p, whichWindow)) OF
-
- inDesk: SysBeep(10);
-
- inGoAway:
- IF Ours(whichWindow) THEN
- IF TrackGoAway(whichWindow, p) THEN
- IssueCloseCommand(whichWindow);
-
- inMenuBar:
- BEGIN
- SetCursor(arrow);
- theDoc := DPtrFromWindowPtr(FrontWindow);
- IF (theDoc <> NIL) THEN
- BEGIN
- SetFontMenu(theDoc);
- SetEditMenu(theDoc);
- END;
-
- DoCommand(MenuSelect(p));
- HiliteMenu(0);
- END;
-
- inSysWindow: SystemClick(myEvent, whichWindow);
-
- inDrag:
- BEGIN
- dragRect := screenBits.bounds;
-
- IF (Ours(whichWindow)) THEN
- BEGIN
- DragWindow(whichWindow, p, dragRect);
- (*
- As rgnBBox may be passed by address
- *)
- dragRect := WindowPeek(whichWindow)^.strucRgn^^.rgnBBox;
- (*
- The windows already there, but still tell
- the our AppleEvents core about the move in case
- they want to do anything
- *)
- IssueMoveWindow(whichWindow, dragRect);
- END;
- END;
-
- inGrow: BEGIN
- SetCursor(Arrow);
- IF (Ours(whichWindow)) THEN
- MyGrowWindow(whichWindow, p);
- END;
-
- inZoomIn : DoZoom(whichWindow, inZoomIn, p);
-
- inZoomOut: DoZoom(whichWindow, inZoomOut, p);
-
- inContent:
- IF (whichWindow <> FrontWindow) THEN
- SelectWindow(whichWindow)
- ELSE
- IF (Ours(whichWindow)) THEN
- DoContent(whichWindow, myEvent);
-
- END; {of CASE}
- END;
-
- {$S Main}
-
- FUNCTION GetSleep: Longint;
-
- {get the sleep value}
-
- VAR
- sleep : Longint;
- theWindow : WindowPtr;
- theDoc : DPtr;
-
- BEGIN
- sleep := MAXLONGINT;
- IF NOT gInBackground THEN
- BEGIN
- theWindow := FrontWindow;
- IF (theWindow <> NIL) THEN
- BEGIN
- theDoc := DPtrFromWindowPtr(theWindow);
- IF (theDoc^.theText^^.selStart = theDoc^.theText^^.selEnd) THEN
- sleep := GetCaretTime;
- END;
- END;
- GetSleep := sleep;
- END; {GetSleep}
-
- {$S Main}
-
- PROCEDURE MainEvent;
-
- VAR
- theDoc : DPtr;
- myEvent : EventRecord;
- theChar : Char;
- err : INTEGER;
- theWindow : WindowPtr;
- activate : BOOLEAN;
- keyIsOk : BOOLEAN;
- currSection : SectHandle;
-
- BEGIN
-
- MaintainCursor; (* TEIdle in here for now *)
- MaintainMenus;
-
- IF WaitNextEvent(everyEvent, myEvent, GetSleep, NIL) THEN
- BEGIN
- CASE myEvent.what OF
- mouseDown: BEGIN
- FlushAndRecordTypingBuffer;
- DoMouseDown(myEvent);
- END;
- keydown, autoKey:
- BEGIN
- theDoc := DPtrFromWindowPtr(FrontWindow);
-
- theChar := CHR(BitAnd(myEvent.message, charcodemask));
-
- IF BitAnd(myEvent.ModIfiers, CmdKey) = CmdKey THEN
- BEGIN
- DoCommand(MenuKey(theChar));
- HiliteMenu(0);
- END
- ELSE
- IF theDoc^.theText <> NIL THEN
- BEGIN
- keyIsOk := TRUE;
- (*
- don't allow a subscriber to be changed
- *)
- currSection := GetSection(theDoc^.theText^^.selStart,
- theDoc^.theText^^.selEnd,
- theDoc);
-
- IF (currSection <> NIL) THEN
- IF (currSection^^.fSecthandle^^.kind = stSubscriber) THEN
- keyIsOk := KeyOKinSubscriber(theChar);
-
- IF keyIsOK THEN
- BEGIN
-
- DoTEKeySectionRecalc(theDoc, theChar);
-
- AddKeyToTypingBuffer(theDoc, theChar);
-
- TEKey(theChar, theDoc^.theText);
- AdjustScrollbars(theDoc, FALSE);
-
- ShowSelect(theDoc);
-
- theDoc^.dirty := TRUE;
- END;
- END;
- END;
-
- activateEvt:
- BEGIN
- activate := (BitAnd(myEvent.ModIfiers, ActiveFlag) <> 0);
- theWindow := WindowPtr(myEvent.message);
- DoActivate(theWindow, activate);
- END;
-
- updateEvt:
- BEGIN
- theDoc := DPtrFromWindowPtr(WindowPtr(myEvent.message));
- DoUpdate(theDoc);
- END;
-
- kHighLevelEvent: BEGIN
- FlushAndRecordTypingBuffer;
- DoAppleEvent(myEvent);
- END;
-
- kOSEvent:
- CASE BAnd(BRotL(myEvent.message, 8), $FF) OF {high byte of message}
- kSuspENDResumeMessage:
- BEGIN
- gInBackground := BAnd(myEvent.message, kResumeMask) = 0;
- DoActivate(FrontWindow, NOT gInBackground);
- END;
- END;
- END;
- END; {of CASE}
- END;
-
- {$S Main}
-
- PROCEDURE DoSVEdit;
-
- VAR
- err : OSErr;
- result : INTEGER;
-
- BEGIN
-
- InitGraf(@thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
-
- MaxApplZone;
- SetUpCursors;
-
- SetUpMenus;
-
- gWCount := 0;
- gNewDocCount := 0;
- gQuitting := FALSE;
- gFontMItem := 0;
-
- {initialise the global functionality booleans, so we can run under both}
- {6.0x and 7.0}
-
- gGestaltAvailable := FALSE;
- gAppleEventsImplemented := FALSE;
- gAliasManagerImplemented := FALSE;
- gEditionManagerImplemented := FALSE;
- gOutlineFontsImplemented := FALSE;
-
- {check environment checks to see if we are running 7.0}
- IF NOT CheckEnvironment THEN
- BEGIN
- SetCursor(arrow);
- {pose the only 7.0 alert}
- result := Alert(302, NIL);
- Exit(DoSVEdit);
- END;
-
- err := InitEditionPack;
- IF err <> noErr THEN
- BEGIN
- ShowError('InitEditionPack', err);
- gQuitting := TRUE;
- END;
-
- err := AEObjectInit;
- IF err <> noErr THEN
- BEGIN
- ShowError('AEObjectInit', err);
- gQuitting := TRUE;
- END;
-
- InitAppleEvents;
-
- err := PPCInit;
- IF err <> noErr THEN
- BEGIN
- ShowError('PPCInit', err);
- gQuitting := TRUE;
- END;
-
- WHILE NOT gQuitting DO
- MainEvent;
-
- END;
-
- BEGIN
- {the main routine starts here}
- DoSVEdit;
- END.
-